package com.futuristik.objects;

import aurelienribon.box2deditor.FixtureAtlas;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.futuristik.arkitek.Character;

public class Spikes extends ArkitekObject {

	World world;
	TextureRegion sprite;
	Vector2[] v;
	FixtureAtlas atlas;	
	
	public final static float width = 1;
	public final static float height = 1;
	
	public Spikes(float x, float y){	
		this(x, y, 0);
	}
	
	public Spikes(float x, float y, float angle){	
		super(x, y, angle);
		
		//Texture info goes here..
		sprite = new TextureRegion(new Texture(Gdx.files.internal("data/obj/spikesSprite.png"))); 
	}
	
	public void create(World w){
		world = w;
		
		//This object used an advanced body generation technique
		//atlas = new FixtureAtlas(Gdx.files.internal("data/obj/obstacles.bin"));
				
		BodyDef def = new BodyDef(); //initialize Body definition to begin the creation
		def.position.set(new Vector2(x, y));
		objectBody = w.createBody(def); //creates a body from the definition and adds it to the World's list of bodies
 
		PolygonShape poly = new PolygonShape();		
		poly.setAsBox(width, height, new Vector2(width, height),  angle); //creates the polygon as a box of given width and height
		FixtureDef fDef = new FixtureDef();
			fDef.friction = 0;
			fDef.shape = poly;
		objectBody.createFixture(fDef); //this attaches the "fixture" to the body
		
		//atlas.createFixtures(objectBody,"spikes\\spikeSprite.png", 2, 2); //COOL IDEA TOO BAD IT DOESN'T WORK OUT
	}
	
	public void topContact(Character player){
		if(player.state != Character.DYING && player.state != Character.DEAD){
			player.state = Character.DYING;
			player.stateTime = 0f;
		}
	}
	
	public void render(SpriteBatch batch){
		batch.draw(sprite, x, y, 1, 1, 2, 2, 1, 1, angle * MathUtils.radiansToDegrees);    
	}
	
}
